package com.yequan.exe.business;

import com.yequan.exe.core.ExeExecutorExtListener;
import com.yequan.exe.core.annotation.ExeService;
import com.yequan.exe.core.handler.AbstractExeHandler;
import com.yequan.pojo.CalcData;
import com.yequan.pojo.ExeInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author yq
 * @date 2020/09/30
 */
@ExeService("pingExeHandler")
public class PingExeHandler extends AbstractExeHandler implements ExeExecutorExtListener {

    @Override
    public void combineCommand(CalcData calcData) {
        List<String> command = new ArrayList<>();
        ExeInfo exeInfo = calcData.getExeInfo();
        Map<String, String> paramMap = exeInfo.getParamMap();
        command.add(exeInfo.getExeName());
        command.add(paramMap.get("ip"));
        command.add(paramMap.get("n"));
        command.add(paramMap.get("count"));
        exeInfo.setCommand(command);
    }


    @Override
    public ExeExecutorExtListener getExeExecutorListener() {
        return this;
    }

    @Override
    public void afterExecuteExt(CalcData calcData, int result) {
        System.out.println(Thread.currentThread().getName() + "执行结果：" + result);
    }

    @Override
    public boolean preLogSendFilter(String line) {
//        if (line.contains("127.0.0.1")) {
//            return true;
//        }
        return false;
    }
}
